<template>
  <div class="app-container">
    <div v-if="jiBie == 2">
      <el-form>
        <el-form-item label="当前站点余额">{{ balance || 0 }}</el-form-item>
      </el-form>
    </div>
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="68px"
      class="globalSerchFormStyle"
    >
      <el-row>
        <el-col :span="6">
          <el-form-item label="类型" prop="type">
            <el-select
              v-model="queryParams.type"
              placeholder="请选择消费充值类型"
              clearable
              size="small"
            >
              <el-option label="充值" value="+" />
              <el-option label="消费" value="-" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row class="global_el_rowStyle" :gutter="10">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
          type="primary"
          plain
          >重置</el-button
        >
      </el-col>
    </el-row>
    <el-table :data="balanceAdjustList" stripe>
      <el-table-column label="类型" align="left" prop="type">
        <template slot-scope="scope">
          <span
            class="badge"
            :class="scope.row.type == '+' ? 'badge-primary' : 'badge-danger'"
            >{{ scope.row.type == "+" ? "增加" : "减少" }}</span
          >
        </template>
      </el-table-column>
      <af-table-column label="变动金额(元)" align="left" prop="amt" />
      <af-table-column
        label="站点名称"
        align="left"
        prop="stationName"
        v-if="jiBie == 1"
      />
      <af-table-column label="调价时间" align="left" prop="createTime" />
      <el-table-column label="涉及订单" align="left" prop="type">
        <template slot-scope="scope">
          <span>{{
            scope.row.orderNo == null ? "无" : scope.row.orderNo
          }}</span>
        </template>
      </el-table-column>
      <af-table-column label="操作人" align="left" prop="createName" />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listAdjust, listBanlaceAdjust, selectDeptBalance } from "@/api/lng";

export default {
  name: "Lng_BalaceRecord",
  data() {
    return {
      // 总条数
      total: 0,
      // 结算价格，司机价格优惠调整表格数据
      balanceAdjustList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        levelId: this.levelId,
        pageNum: 1,
        pageSize: 10,
        settlementPrice: null,
        settlementType: null,
        driverPrice: null,
        stationId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      balance: 0,
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      this.getList();
      this.selectDeptBalance();
    },
    selectDeptBalance() {
      selectDeptBalance()
        .then((res) => {
          if (res.code == 200) {
            this.balance = res.data.balance;
          } else {
            throw new Error("");
          }
        })
        .catch((err) => {
          this.msgError("加载余额失败~");
        });
    },
    /** 查询结算价格，司机价格优惠调整列表 */
    getList() {
      this.queryParams.levelId = this.levelId;
      listBanlaceAdjust(this.queryParams).then((response) => {
        this.balanceAdjustList = response.rows;
        this.total = response.total;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.levelId = this.levelId;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
